home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
lib
/
xdisplayfile.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
4KB
|
133 lines
; $Id: xdisplayfile.pro,v 1.10 1997/01/15 03:11:50 ali Exp $
;
; Copyright (c) 1991-1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
PRO XDispFile_evt, event
WIDGET_CONTROL, GET_UVALUE = retval, event.id
IF (retval EQ "EXIT") THEN WIDGET_CONTROL, event.top, /DESTROY
END
PRO XDisplayFile, FILENAME, TITLE = TITLE, GROUP = GROUP, WIDTH = WIDTH, $
HEIGHT = HEIGHT, TEXT = TEXT, FONT = font, $
DONE_BUTTON=done_button
;+
; NAME:
; XDISPLAYFILE
;
; PURPOSE:
; Display an ASCII text file using widgets and the widget manager.
;
; CATEGORY:
; Widgets.
;
; CALLING SEQUENCE:
; XDISPLAYFILE, Filename
;
; INPUTS:
; Filename: A scalar string that contains the filename of the file
; to display. The filename can include a path to that file.
;
; KEYWORD PARAMETERS:
; DONE_BUTTON: the text to use for the Done button. If omitted,
; the text "Done with <filename>" is used.
; FONT: The name of the font to use. If omitted use the default
; font.
; GROUP: The widget ID of the group leader of the widget. If this
; keyword is specified, the death of the group leader results in
; the death of XDISPLAYFILE.
;
; HEIGHT: The number of text lines that the widget should display at one
; time. If this keyword is not specified, 24 lines is the
; default.
;
; TEXT: A string or string array to be displayed in the widget
; instead of the contents of a file. This keyword supercedes
; the FILENAME input parameter.
;
; TITLE: A string to use as the widget title rather than the file name
; or "XDisplayFile".
;
; WIDTH: The number of characters wide the widget should be. If this
; keyword is not specified, 80 characters is the default.
;
; OUTPUTS:
; No explicit outputs. A file viewing widget is created.
;
; SIDE EFFECTS:
; Triggers the XMANAGER if it is not already in use.
;
; RESTRICTIONS:
; None.
;
; PROCEDURE:
; Open a file and create a widget to display its contents.
;
; MODIFICATION HISTORY:
; Written By Steve Richards, December 1990
; Graceful error recovery, DMS, Feb, 1992.
; 12 Jan. 1994 - KDB
; If file was empty, program would crash. Fixed.
; 4 Oct. 1994 MLR Fixed bug if /TEXT was present and /TITLE was not.
; 2 jan 1997 DMS Added DONE_BUTTON keyword, made Done
; button align on left, removed padding.
;-
;use the defaults if
IF(NOT(KEYWORD_SET(HEIGHT))) THEN HEIGHT = 24 ;the keywords were not
IF(NOT(KEYWORD_SET(WIDTH))) THEN WIDTH = 80 ;passed in
IF(NOT(KEYWORD_SET(TEXT))) THEN BEGIN
IF(NOT(KEYWORD_SET(TITLE))) THEN TITLE = FILENAME
OPENR, unit, FILENAME, /GET_LUN, ERROR=i ;open the file and then
if i lt 0 then begin ;OK?
a = [ !err_string, ' Can not display ' + filename] ;No
endif else begin
maxlines = 10000 ;Maximum # of lines in file
a = strarr(maxlines)
on_ioerror, done_reading
readf, unit, a
done_reading: s = fstat(unit) ;Get # of lines actually read
a = a[0: (s.transfer_count-1) > 0]
on_ioerror, null
FREE_LUN, unit ;free the file unit.
endelse
ENDIF ELSE BEGIN
IF(NOT(KEYWORD_SET(TITLE))) THEN TITLE = 'XDisplayFile'
a = TEXT
ENDELSE
filebase = WIDGET_BASE(TITLE = TITLE, $ ;create the base
/BASE_ALIGN_LEFT, /COLUMN)
; SPACE = 20, XPAD = 20, YPAD = 20)
; Default Done button name:
if n_elements(done_button) eq 0 then done_button = "Done with " + TITLE
filequit = WIDGET_BUTTON(filebase, $ ;create a Done Button
VALUE = done_button, UVALUE = "EXIT")
IF n_elements(font) gt 0 then $
filetext = WIDGET_TEXT(filebase, $ ;create a text widget
XSIZE = WIDTH, $ ;to display the file's
YSIZE = HEIGHT, $ ;contents
/SCROLL, FONT = font, $
VALUE = a) $
ELSE filetext = WIDGET_TEXT(filebase, $ ;create a text widget
XSIZE = WIDTH, $ ;to display the file's
YSIZE = HEIGHT, $ ;contents
/SCROLL, $
VALUE = a)
WIDGET_CONTROL, filebase, /REALIZE ;instantiate the widget
Xmanager, "XDisplayFile", $ ;register it with the
filebase, $ ;widget manager
GROUP_LEADER = GROUP, $
EVENT_HANDLER = "XDispFile_evt", /NO_BLOCK
END ;--------------------- procedure XDisplayFile ----------------------------